package singleton;

/**
 * 懒汉式 + Synchronized
 * 使用时再创建
 */
public class Singleton05 {

    private static Singleton05 INSTANCE;

    private Singleton05(){}

    public static synchronized Singleton05 getInstance(){
        //悲观锁，性能低
        if (INSTANCE == null){
            INSTANCE = new Singleton05();
        }
        return INSTANCE;
    }


    public static void main(String[] args) {
        Singleton05 i1 = Singleton05.getInstance();
        Singleton05 i2 = Singleton05.getInstance();
        System.out.println(i1 == i2);
    }
}
